package com.qyer.search.model;

/**
 * User: Z J Wu Date: 2015/08/13 Time: 15:58 Package: com.qyer.dsp.model
 */
public class SecondComparableTuple2<O, P extends Comparable<P>> implements Comparable<SecondComparableTuple2<O, P>> {

  private O first;

  private P second;

  public SecondComparableTuple2(O first, P second) {
    this.first = first;
    this.second = second;
  }

  public O getFirst() {
    return first;
  }

  public void setFirst(O first) {
    this.first = first;
  }

  public P getSecond() {
    return second;
  }

  public void setSecond(P second) {
    this.second = second;
  }

  @Override public String toString() {
    return "Tuple2(" + first + ", " + second + ')';
  }

  @Override public int compareTo(SecondComparableTuple2<O, P> o) {
    if (this.second == null || o.getSecond() == null) {
      return 0;
    }
    return this.second.compareTo(o.getSecond());
  }

  public boolean isSame() {
    O first = getFirst();
    P second = getSecond();
    if (first == null && second == null) {
      return true;
    } else if (((first == null) && (second != null)) || ((first != null) && (second == null))) {
      return false;
    } else {
      return this.getFirst().equals(this.getSecond());
    }
  }
}
